package com.sourceQ.system.controller.message.sms;

import com.sourceQ.common.core.utils.servlet.ServletUtils;
import com.sourceQ.common.core.web.controller.BaseController;
import com.sourceQ.common.core.web.domain.AjaxResult;
import com.sourceQ.common.sms.core.enums.SmsChannelEnum;
import com.sourceQ.system.service.message.sms.SmsSendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.security.PermitAll;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/sms-callback")
@Api(tags = "短信回调")
public class SmsCallBackController extends BaseController {

    @Autowired
    private SmsSendService smsSendService;

    @PostMapping("/aliyun")
    @PermitAll
    @ApiOperation("阿里云短信的回调")//"参见 https://help.aliyun.com/zh/sms/developer-reference/configure-delivery-receipts-1 文档"
    public AjaxResult receiveAliyunSmsStatus(HttpServletRequest request) throws Throwable {
        String text = ServletUtils.getBody(request);
        smsSendService.receiveSmsStatus(SmsChannelEnum.ALIYUN.getCode(), text);
        return success(true);
    }

    @PostMapping("/tencent")
    @PermitAll
    @ApiOperation("腾讯云短信的回调")//"参见 https://cloud.tencent.com/document/product/382/59178 文档"
    public AjaxResult receiveTencentSmsStatus(HttpServletRequest request) throws Throwable {
        String text = ServletUtils.getBody(request);
        smsSendService.receiveSmsStatus(SmsChannelEnum.TENCENT.getCode(), text);
        return success(true);
    }
}
